import 'dart:convert';

import 'package:flutter/foundation.dart';

class MoviesEntity {
  List<MoviesData>? data;
  double? createdAt;
  double? updatedAt;
  String? id;
  String? originalName;
  double? imdbVotes;
  String? imdbRating;
  String? rottenRating;
  double? rottenVotes;
  String? year;
  String? imdbId;
  String? alias;
  String? doubanId;
  String? type;
  String? doubanRating;
  double? doubanVotes;
  double? duration;
  String? dateReleased;
  MoviesEntity({
    this.data,
    this.createdAt,
    this.updatedAt,
    this.id,
    this.originalName,
    this.imdbVotes,
    this.imdbRating,
    this.rottenRating,
    this.rottenVotes,
    this.year,
    this.imdbId,
    this.alias,
    this.doubanId,
    this.type,
    this.doubanRating,
    this.doubanVotes,
    this.duration,
    this.dateReleased,
  });

  MoviesEntity copyWith({
    List<MoviesData>? data,
    double? createdAt,
    double? updatedAt,
    String? id,
    String? originalName,
    double? imdbVotes,
    String? imdbRating,
    String? rottenRating,
    double? rottenVotes,
    String? year,
    String? imdbId,
    String? alias,
    String? doubanId,
    String? type,
    String? doubanRating,
    double? doubanVotes,
    double? duration,
    String? dateReleased,
  }) {
    return MoviesEntity(
      data: data ?? this.data,
      createdAt: createdAt ?? this.createdAt,
      updatedAt: updatedAt ?? this.updatedAt,
      id: id ?? this.id,
      originalName: originalName ?? this.originalName,
      imdbVotes: imdbVotes ?? this.imdbVotes,
      imdbRating: imdbRating ?? this.imdbRating,
      rottenRating: rottenRating ?? this.rottenRating,
      rottenVotes: rottenVotes ?? this.rottenVotes,
      year: year ?? this.year,
      imdbId: imdbId ?? this.imdbId,
      alias: alias ?? this.alias,
      doubanId: doubanId ?? this.doubanId,
      type: type ?? this.type,
      doubanRating: doubanRating ?? this.doubanRating,
      doubanVotes: doubanVotes ?? this.doubanVotes,
      duration: duration ?? this.duration,
      dateReleased: dateReleased ?? this.dateReleased,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'data': data?.map((x) => x?.toMap())?.toList(),
      'createdAt': createdAt,
      'updatedAt': updatedAt,
      'id': id,
      'originalName': originalName,
      'imdbVotes': imdbVotes,
      'imdbRating': imdbRating,
      'rottenRating': rottenRating,
      'rottenVotes': rottenVotes,
      'year': year,
      'imdbId': imdbId,
      'alias': alias,
      'doubanId': doubanId,
      'type': type,
      'doubanRating': doubanRating,
      'doubanVotes': doubanVotes,
      'duration': duration,
      'dateReleased': dateReleased,
    };
  }

  factory MoviesEntity.fromMap(Map<String, dynamic> map) {
    return MoviesEntity(
      data: map['data'] != null
          ? List<MoviesData>.from(
              map['data']?.map((x) => MoviesData.fromMap(x)))
          : null,
      createdAt: map['createdAt']?.toDouble(),
      updatedAt: map['updatedAt']?.toDouble(),
      id: map['id'],
      originalName: map['originalName'],
      imdbVotes: map['imdbVotes']?.toDouble(),
      imdbRating: map['imdbRating'],
      rottenRating: map['rottenRating'],
      rottenVotes: map['rottenVotes']?.toDouble(),
      year: map['year'],
      imdbId: map['imdbId'],
      alias: map['alias'],
      doubanId: map['doubanId'],
      type: map['type'],
      doubanRating: map['doubanRating'],
      doubanVotes: map['doubanVotes']?.toDouble(),
      duration: map['duration']?.toDouble(),
      dateReleased: map['dateReleased'],
    );
  }

  String toJson() => json.encode(toMap());

  factory MoviesEntity.fromJson(String source) =>
      MoviesEntity.fromMap(json.decode(source));

  @override
  String toString() {
    return 'MoviesEntity(data: $data, createdAt: $createdAt, updatedAt: $updatedAt, id: $id, originalName: $originalName, imdbVotes: $imdbVotes, imdbRating: $imdbRating, rottenRating: $rottenRating, rottenVotes: $rottenVotes, year: $year, imdbId: $imdbId, alias: $alias, doubanId: $doubanId, type: $type, doubanRating: $doubanRating, doubanVotes: $doubanVotes, duration: $duration, dateReleased: $dateReleased)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is MoviesEntity &&
        listEquals(other.data, data) &&
        other.createdAt == createdAt &&
        other.updatedAt == updatedAt &&
        other.id == id &&
        other.originalName == originalName &&
        other.imdbVotes == imdbVotes &&
        other.imdbRating == imdbRating &&
        other.rottenRating == rottenRating &&
        other.rottenVotes == rottenVotes &&
        other.year == year &&
        other.imdbId == imdbId &&
        other.alias == alias &&
        other.doubanId == doubanId &&
        other.type == type &&
        other.doubanRating == doubanRating &&
        other.doubanVotes == doubanVotes &&
        other.duration == duration &&
        other.dateReleased == dateReleased;
  }

  @override
  int get hashCode {
    return data.hashCode ^
        createdAt.hashCode ^
        updatedAt.hashCode ^
        id.hashCode ^
        originalName.hashCode ^
        imdbVotes.hashCode ^
        imdbRating.hashCode ^
        rottenRating.hashCode ^
        rottenVotes.hashCode ^
        year.hashCode ^
        imdbId.hashCode ^
        alias.hashCode ^
        doubanId.hashCode ^
        type.hashCode ^
        doubanRating.hashCode ^
        doubanVotes.hashCode ^
        duration.hashCode ^
        dateReleased.hashCode;
  }
}

class MoviesData {
  double? createdAt;
  double? updatedAt;
  String? id;
  String? poster;
  String? name;
  String? genre;
  String? description;
  String? language;
  String? country;
  String? lang;
  String? shareImage;
  String? movie;
  MoviesData({
    this.createdAt,
    this.updatedAt,
    this.id,
    this.poster,
    this.name,
    this.genre,
    this.description,
    this.language,
    this.country,
    this.lang,
    this.shareImage,
    this.movie,
  });

  MoviesData copyWith({
    double? createdAt,
    double? updatedAt,
    String? id,
    String? poster,
    String? name,
    String? genre,
    String? description,
    String? language,
    String? country,
    String? lang,
    String? shareImage,
    String? movie,
  }) {
    return MoviesData(
      createdAt: createdAt ?? this.createdAt,
      updatedAt: updatedAt ?? this.updatedAt,
      id: id ?? this.id,
      poster: poster ?? this.poster,
      name: name ?? this.name,
      genre: genre ?? this.genre,
      description: description ?? this.description,
      language: language ?? this.language,
      country: country ?? this.country,
      lang: lang ?? this.lang,
      shareImage: shareImage ?? this.shareImage,
      movie: movie ?? this.movie,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'createdAt': createdAt,
      'updatedAt': updatedAt,
      'id': id,
      'poster': poster,
      'name': name,
      'genre': genre,
      'description': description,
      'language': language,
      'country': country,
      'lang': lang,
      'shareImage': shareImage,
      'movie': movie,
    };
  }

  factory MoviesData.fromMap(Map<String, dynamic> map) {
    return MoviesData(
      createdAt: map['createdAt']?.toDouble(),
      updatedAt: map['updatedAt']?.toDouble(),
      id: map['id'],
      poster: map['poster'],
      name: map['name'],
      genre: map['genre'],
      description: map['description'],
      language: map['language'],
      country: map['country'],
      lang: map['lang'],
      shareImage: map['shareImage'],
      movie: map['movie'],
    );
  }

  String toJson() => json.encode(toMap());

  factory MoviesData.fromJson(String source) =>
      MoviesData.fromMap(json.decode(source));

  @override
  String toString() {
    return 'MoviesData(createdAt: $createdAt, updatedAt: $updatedAt, id: $id, poster: $poster, name: $name, genre: $genre, description: $description, language: $language, country: $country, lang: $lang, shareImage: $shareImage, movie: $movie)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is MoviesData &&
        other.createdAt == createdAt &&
        other.updatedAt == updatedAt &&
        other.id == id &&
        other.poster == poster &&
        other.name == name &&
        other.genre == genre &&
        other.description == description &&
        other.language == language &&
        other.country == country &&
        other.lang == lang &&
        other.shareImage == shareImage &&
        other.movie == movie;
  }

  @override
  int get hashCode {
    return createdAt.hashCode ^
        updatedAt.hashCode ^
        id.hashCode ^
        poster.hashCode ^
        name.hashCode ^
        genre.hashCode ^
        description.hashCode ^
        language.hashCode ^
        country.hashCode ^
        lang.hashCode ^
        shareImage.hashCode ^
        movie.hashCode;
  }
}
